/*
 * File Name：TrackBase.java
 * Copyright：Copyright 2008-2012 CiWong.Inc. All Rights Reserved.
 * Description： TrackBase.java
 * Modify By：PLA-ZJLIU
 * Modify Date：2012-12-7
 * Modify Type：Add
 */
package com.ciwong.ciwongwrite.mode;

import java.io.Serializable;

import android.graphics.Canvas;
import android.graphics.Color;

/**
 * 
 * <pre>
 * </pre>
 * 
 * @author PLA-ZJLIU
 * @version ciwong v.1.0 2012-12-7
 * @since ciwong v.1.0
 */
public abstract class TrackBase implements Serializable
{
    /**
     * TODO field comment
     */
    private static final long serialVersionUID = 1L;

    public static final int FRAME = 50;

    /**
     * 每一秒插入几次时间戳
     */
    public static final int TIME_STAMP = 4;

    public static final int COLOR_0 = Color.BLACK;

    public static final int COLOR_1 = Color.RED;

    public static final int COLOR_2 = Color.BLUE;

    public static final int COLOR_3 = Color.GREEN;

    public static final int WIDTH_0 = 2;

    public static final int WIDTH_1 = 4;

    public static final int WIDTH_2 = 6;

    public static final int WIDTH_3 = 8;

    public static final int EASER_WIDTH = 40; //橡皮擦大小

    /**
     * 
     */
    public static final int TRACK_ACTION_NORMAL = -1;

    /**
     * 鼠标移动
     */
    public static final int TRACK_ACTION_MOUSE = 0;

    /**
     * 插入图片
     */
    public static final int TRACK_ACTION_PHOTO = 1;

    /**
     * 清屏
     */
    public static final int TRACK_ACTION_CLS = 2;

    /**
     * 橡皮搽
     */
    public static final int TRACK_ACTION_EASER = 3;

    /**
     * 时间节点
     */
    public static final int TRACK_ACTION_TIME_STAMP = 4;

    /**
     * frame
     */
    public static final String XML_ROOT = "Frame";

    /**
     * node
     */
    public static final String NODE = "n";

    /**
     * end
     */
    public static final String END = "End";

    /**
     * Error
     */
    public static final String ERROR = "Error";

    /**
     * value属性名
     */
    public static final String HEADER_VALUE = "value";

    /**
     * value属性名
     */
    public static final String VALUE = "v";

    /**
     * 头部name属性名
     */
    public static final String HEADER_NAME_ATTR = "name";

    /**
     * name属性名
     */
    public static final String NAME_ATTR = "n";

    /**
     * 头部参数
     */
    public static final String PARAM_ATTR = "param";

    /**
     * 鼠标动作
     */
    public static final String MOUSE_NODE = "M";

    /**
     * 插入相片动作
     */
    public static final String PHOTO_NODE = "P";

    /**
     * 时间戳
     */
    public static final String TIME_NODE = "T";

    /**
     * 清屏动作
     */
    public static final String CLEAR_NODE = "C";

    /**
     * 创建时间属性名
     */
    public static final String CREATE_TIME = "CreateTime";

    /**
     * 视频时长属性名
     */
    public static final String REC_TIME = "RecTime";

    /**
     * 长度
     */
    public static final String WIDTH = "Width";

    /**
     * 高度
     */
    public static final String HEIGHT = "Height";

    /**
     * 背景颜色
     */
    public static final String BG_COLOR = "BgColor";

    /**
     * 总帧数
     */
    public static final String TOTAL_FRAMES = "TotalFrames";

    protected static Canvas mCanvas;

    public static void setCanvas(Canvas canvas)
    {
        mCanvas = canvas;
    }

    /**
     * 绘图
     * 
     * @param mCanvas
     *            画布
     */
    public abstract void draw(Canvas mCanvas);

    /**
     * 将动作格式化
     * 
     * @param touchDown
     *            手指是否按下
     * @return 格式化的字符串
     */
    public abstract String format(boolean touchDown);

    /**
     * 获取当前播放的时间戳<br />
     * 需要各子类重载方法
     * 
     * @return 时间戳
     */
    public int getTimeSpan()
    {
        return 0;
    }

    /**
     * 转换颜色
     * 
     * @param colorIndex
     *            颜色值索引
     * @return 颜色值
     */
    public static int convertColorByIndex(int colorIndex)
    {
        switch (colorIndex)
        {
            case 1:
                return COLOR_1;
            case 2:
                return COLOR_2;
            case 3:
                return COLOR_3;
            default:
                return COLOR_0;
        }
    }

    /**
     * 转换画笔大小
     * 
     * @param //width
     *            画笔索引
     * @return 画笔大小
     */
    public static int convertWidthIndexByIndex(int index)
    {
        switch (index)
        {
            case 0:
                return WIDTH_0;
            case 1:
                return WIDTH_1;
            case 2:
                return WIDTH_2;
            case 3:
                return WIDTH_3;
            default:
                return WIDTH_0;
        }
    }

    /**
     * 转换画笔大小
     * 
     * @param width
     *            画笔大小
     * @return 画笔大小索引
     */
    public static int convertWidthIndexByWidth(int width)
    {
        switch (width)
        {
            case WIDTH_0:
                return 0;
            case WIDTH_1:
                return 1;
            case WIDTH_2:
                return 2;
            default:
                return 3;
        }
    }

    /**
     * 转换颜色索引
     * 
     * @param color
     *            颜色
     * @return 颜色索引
     */
    public static int convertColorIndexByColor(int color)
    {
        switch (color)
        {
            case COLOR_1:
                return 1;
            case COLOR_2:
                return 2;
            case COLOR_3:
                return 3;
            default:
                return 0;
        }
    }
}
